<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/ProjetWebEAR/css/main.css" />
<title>Liste des employés</title>
<%@ page import="com.javaee.ejb.entity.Employee"%>
<%@ page import="com.javaee.ejb.session.EmployeeManagerRemote"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.DateFormat"%>
<%@ page import="java.text.SimpleDateFormat"%>
</head>
<body>
<div id="wrapper">
		<h1>Liste des employés</h1>

<div id="employee">
<%
	List<Employee> employees = (List<Employee>) request.getAttribute("listEmployees");
	DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	if (!employees.isEmpty()) {
%>		
		<table>
		<thead>
		<tr>
			<th>Username</th>
			<th>First name</th>
			<th>Last name</th>
			<th>Email</th>
			<th>Birthdate</th>
			<th>Indate</th>
			<th>Modify</th>
			<th>Delete</th>			
		</tr>
		</thead>
		<tbody>		
<%	
		Iterator<Employee> iter = employees.iterator();
		while (iter.hasNext()) {
			Employee element = iter.next();
			Date birthdate = element.getBirthdate();
			Date indate = element.getIndate();
			String sBirthdate = dateFormat.format(birthdate);
			String sIndate = dateFormat.format(indate);
%>
			<tr>
				<td><%= element.getUsername() %></td>
				<td><%= element.getFirstname() %></td>
				<td><%= element.getLastname() %></td>			
				<td><%= element.getEmail() %></td>
				<td><%= sBirthdate %></td>
				<td><%= sIndate %></td>
				<td><a href="/ProjetWebEAR/EmployeServlet?action=modif&id=<%= element.getIdemployee()%>">Modifier</a></td>
				<td>
					<a href="/ProjetWebEAR/EmployeServlet?action=delete&id=<%= element.getIdemployee()%>">Supprimer</a>
				</td>
			</tr>
			<% } %>
			</tbody>
		</table>
	<% } %>
		<a href="/ProjetWebEAR/EmployeServlet?action=modif">Créer un employé</a>
</div>
</div>
</body>
</html>